// -*- coding: utf-8 -*- 
/**
 * Project: LanQiao
 * Creator: yanking
 * Create time: 2022-02-20 19:21
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package sinDance;

public class sinDance {
    // 有规律的字符串输出
    public String[] An; // 各项子式
    public String Sn; // 最终表达式，由各项子式构成

    /**
     * @param n: the number of the An
     */
    public String initAn(int n) {
        String s = "sin(";
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < n; i++) {
            builder.append(s);
            builder.append(i + 1);
            if (i == n - 1) {
                break;
            }
            if (i % 2 == 0) {
                builder.append('-');
            } else {
                builder.append('+');
            }
        }
        for (int i = 0; i < n; i++) {
            builder.append(')');
        }
        return builder.toString();
    }

    public String getSn(int n) {
        // 初始化An数组方便直接调用
        An = new String[n];
        for (int i = 0; i < n; i++) {
            An[i] = initAn(i + 1);
        }
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < n - 1; i++) {
            builder.append('(');
        }
        for (int i = n; i > 0; i--) {
            builder.append(An[n - i]);
            builder.append('+');
            builder.append(i);
            if (i == 1) break;
            builder.append(')');
        }
        return builder.toString();
    }
}
